<?php

namespace App\Models\Sample;

use App\Models\BaseModel;

class SampleInoutRecordDetail extends BaseModel
{

    protected $table = 'sample_inout_record_details';
    protected $fillable = [
        'sample_inout_record_id', 'sample_id', 'data_scope'
    ];

    public function sample()
    {
        return $this->belongsTo('App\Models\Sample\Sample', 'sample_id');
    }

    /*获取指定发送单包含的样本*/
    public function getOutFormSampleList($limit, $id)
    {
        $perPage = $limit > 0 ? $limit : $this->limit;
        $model = $this->with([
            'sample:id,family_id,family_member_id,sample_type,transport_method,deal_method,sample_date,sampled_by,organization,department,doctor,sample_aim',
            'sample.family:id,code', 'sample.familyMember:id,title,title_amend,code','sample.organization:id,title','sample.department:id,title','sample.doctor:id,title',
            'sample.type:id,title','sample.transportMethod:code,title','sample.dealMethod:code,title','sample.aim:code,title'
        ])
            ->where(['sample_inout_record_id' => $id])
            ->select(['id', 'sample_id']);
        return $model->paginate($perPage)->toArray();
    }
}
